#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=1e6+5;
int n,m;
inline int id(int x,int y){
	return (x-1)*m+y;
}
char s[Maxn];
namespace sub1{
	int ans[22];
	inline bool check(int i,int j){
		if(i<1||j<1||i>n||j>m)return 1;
		return (s[id(i,j)]=='.');
	}
	
	
	inline bool check2(int s,int i,int j){
		if(i<1||j<1||i>n||j>m)return 0;
		return (s>>id(i,j)-1&1);
	}
	inline void solve(){
		int S=0,c=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(s[id(i,j)]=='#'){
					S++;
					c+=check(i,j-1)+check(i,j+1)+check(i+1,j)+check(i-1,j);
				}
			}
		}
		int cnt=min(n*m,(S+c)/5);
		int res=0;
		for(int ss=0;ss<(1<<(n*m));ss++){
			int ok=1;
			if(__builtin_popcount(ss)>cnt)ok=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					if(s[id(i,j)]=='.'&&(ss>>id(i,j)-1&1))ok=0;
					if(s[id(i,j)]=='#'){
						ok&=(check2(ss,i,j)|check2(ss,i-1,j)|check2(ss,i+1,j)|check2(ss,i,j-1)|check2(ss,i,j+1));
						if(!ok)break;
					}
				}
			}
			if(ok){res=ss;break;}
		}
		
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(res>>id(i,j)-1&1)printf("1");
				else{
					if(s[id(i,j)]=='#')printf("0");
					else printf(".");
				}
			}
			puts("");
		}
	}
}
int main(){
	freopen("indian.in","r",stdin);
	freopen("indian.out","w",stdout);
	n=read();m=read();
	for(int i=1;i<=n*m;i++){
		char ch=getchar();
		while(ch!='#'&&ch!='.')ch=getchar();
		s[i]=ch;
	}
	if(n*m<=20)sub1::solve(),exit(0);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[id(i,j)]=='#')printf("1");
			else printf(".");
		}puts("");
	}	
	return 0;
}

